package com.itchen.school.common.base;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

//自定义元数据对象处理器
@Slf4j
@Component
public class BaseBizObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("公共字段自动填充[insert]...");
        metaObject.setValue("sort", 1);
        metaObject.setValue("recordStatus", 1);
        metaObject.setValue("creator", "aaddmmiinn");
        metaObject.setValue("creatorName", "super administrator");
        metaObject.setValue("createTime", String.valueOf(LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli()));
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("公共字段自动填充[update]...");
        metaObject.setValue("updater", "aaddmmiinn");
        metaObject.setValue("updaterName", "super administrator");
        metaObject.setValue("updateTime", String.valueOf(LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli()));
    }

}
